<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Article_m extends MY_Model
{

    const TBL = 'article';
    const UNIQUE_KEY = 'create_time';

    function __construct()
    {
        parent::__construct();
    }

    public function count_articles(){
        $this->db->select('*');
        $this->db->from('article');
        $total = $this->db->count_all_results();
        return $total;
    }

    //翻页及搜索
    public function get_article_list($start, $limit)
    {
        $this->db->select('*');
        $this->db->from('article');
        $this->db->order_by("id", 'desc');
        $this->db->limit($limit, $start);
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result_array();
        }
    }

    public function get_limit_list($num,$field="*")
    {
        $this->db->select($field);
        $this->db->from('article');
        $this->db->order_by("id", 'desc');
        $this->db->limit($num);
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result_array();
        }
    }
}
